<template>
  <div>
    <td>科室名称</td>
    <td><input type="text" v-model="date.kname" /></td>
    <td>创建日期</td>
    <td>
      <input type="date" v-model="date.ldate" />
      ~
      <input type="date" v-model="date.rdate" />
    </td>
    <td><input type="button" value="查询" @click="list" /></td>
    <td><input type="button" value="重置" @click="cz" /></td>
    <td><input type="button" value="导出" @click="exp" /></td>
    <table class="table table-bordered">
      <tbody>
        <tr>
          <td>序号</td>
          <td>科室名称</td>
          <td>科室人数</td>
          <td>科室描述</td>
          <td>创建日期</td>
          <td>操作</td>
        </tr>
        <tr v-for="a in info.list">
          <td>{{ a.kid }}</td>
          <td>{{ a.kname }}</td>
          <td>{{ a.knum }}</td>
          <td>{{ a.kmiao }}</td>
          <td>{{ moment(a.ktime).format("YYYY-MM-DD HH:mm:ss") }}</td>
          <td>
            <input type="button" value="删除" @click="del(a.kid)" />
            <input type="button" value="修改" @click="update(a.kid)" />
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
//测试git
import axios from "axios";
import { reactive, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import moment from "moment";
const route = useRoute();
const router = useRouter();
let info: any = reactive({
  list: [],
});
let date: any = reactive({
  kname: "",
  ldate: "",
  rdate: "",
});
onMounted(() => {
  list();
});
const list = () => {
  axios({
    url: "/api/Keshi/GetKeshi",
    method: "get",
    params: date,
  }).then((res) => {
    console.log(res);
    info.list = res.data;
  });
};
const del = (kid: any) => {
  if (confirm("确认删除吗?")) {
    axios({
      url: "/api/Keshi/Del",
      method: "get",
      params: {
        kid: kid,
      },
    }).then((res) => {
      if (res.data > 0) {
        alert("删除成功");
        list();
        return;
      } else {
        alert("删除失败");
        return;
      }
    });
  }
};
const exp = () => {
  location.href = `http://localhost:5149/api/Keshi/Export`;
};
const update = (kid: any) => {
  router.push({
    path: "/upkeshi",
    query: {
      kid: kid,
    },
  });
};
const cz = () => {
  date.kname = "";
  date.ldate = "";
  date.rdate = "";
};
</script>

<style scoped></style>
